import { Request, toast, vaildMobile } from '../../utils/util.js'
let request = new Request()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    target : '',
    addressList : []
  },

  select (e) {
    if(this.data.target === 'select'){
      let address = this.data.addressList[e.currentTarget.dataset.index]
      let pages = getCurrentPages()
      wx.navigateBack({
        success : () => {
          pages[pages.length - 2].selectAddress(address)
        }
      })
    }
  },

  getAddress () {
    request.get('deliveryaddress', res => {
      if (res.success) {
        let address = res.data.address
        if (address.length > 0) {
          this.setData({ addressList: address })
        }
      }
    })
  },

  onLoad: function (options) {
    let target = options.target || ''
    if(target !== ''){
      this.setData({target : target})
    }

    this.getAddress()
    
  }
})